export const workspaceTemplateConfig = {
  apiVersion: 'tenant.kubesphere.io/v1alpha2',
  kind: 'WorkspaceTemplate',
  metadata: {
    name: 'aaaaa',
    annotations: {
      'kubesphere.io/creator': 'admin',
    },
  },
  spec: {
    template: {
      spec: {
        manager: 'dwdsdss',
      },
      metadata: {
        annotations: {
          'kubesphere.io/creator': 'admin',
        },
      },
    },
  },
}

export const namespaceConfig = {
  apiVersion: 'v1',
  kind: 'Namespace',
  metadata: {
    name: 'fgdgdr',
    labels: {
      'kubesphere.io/workspace': 'ggege-workspace',
    },
    annotations: {
      'kubesphere.io/creator': 'admin',
    },
  },
}

export const deploymentConfig = {
  apiVersion: 'apps/v1',
  kind: 'Deployment',
  metadata: {
    name: 'init-dev-container',
    namespace: 'testproj',
    annotations: {
      'kubesphere.io/alias-name': 'devstar',
      'kubesphere.io/description': '初始化容器',
    },
  },
  spec: {
    replicas: 1,
    selector: {
      matchLabels: {
        app: 'ssh-app1',
      },
    },
    template: {
      metadata: {
        annotations: {
          'custom.annotation/port': 'ssh',
        },
        labels: {
          app: 'ssh-app1',
        },
      },
      spec: {
        containers: [
          {
            name: 'ssh-container1',
            image: 'registry.mengning.com.cn/base/ubuntu',
            command: [
              '/bin/bash',
              '-c',
              "echo 'root:devstar' | chpasswd && useradd -m -s /bin/bash linux && echo 'linux:devstar' | chpasswd && usermod -aG sudo linux && service ssh start && sudo rm /var/run/nologin && tail -f /dev/null",
            ],
            stdin: true,
            tty: true,
            resources: {
              limits: {
                cpu: '2',
                memory: '4096Mi',
              },
              requests: {
                cpu: '0.01',
                memory: '50Mi',
              },
            },
          },
        ],
      },
    },
  },
}

export const serviceConfig = {
  apiVersion: 'v1',
  kind: 'Service',
  metadata: {
    name: 'init-dev-container-ssh-service',
    namespace: 'testproj',
    annotations: {
      'kubesphere.io/type': 'service',
      'kubesphere.io/workspace': 'workspace',
    },
  },
  spec: {
    selector: {
      app: 'ssh-app1',
    },
    type: 'NodePort',
    ports: [
      {
        name: 'ssh',
        port: 22,
        targetPort: 22,
      },
    ],
    nodeSelector: {
      'kubernetes.io/hostname': 'node1',
    },
  },
}

export const secretConfig = {
  kind: 'Secret',
  apiVersion: 'v1',
  metadata: {
    name: 'harbor-secret',
    namespace: 'testt',
    annotations: {
      'kubesphere.io/creator': 'admin',
      'secret.kubesphere.io/force-insecure': 'true',
      'secret.kubesphere.io/is-default-class': 'true',
    },
  },
  data: {
    '.dockerconfigjson':
      'eyJhdXRocyI6eyJodHRwOi8vcmVnaXN0cnkubWVuZ25pbmcuY29tLmNuIjp7InVzZXJuYW1lIjoiYWRtaW4iLCJwYXNzd29yZCI6IkhhcmJvcjEyMzQ1IiwiZW1haWwiOiIiLCJhdXRoIjoiWVdSdGFXNDZTR0Z5WW05eU1USXpORFU9In19fQ==',
  },
  type: 'kubernetes.io/dockerconfigjson',
}

export const ingressConfig = {
  apiVersion: 'networking.k8s.io/v1',
  kind: 'Ingress',
  metadata: {
    name: 'ssh',
    namespace: 'xiafan-project',
  },
  spec: {
    ingressClassName: 'nginx',
    rules: [
      {
        host: 'test.container.mengning.net',
        http: {
          paths: [
            {
              path: '/',
              pathType: 'Prefix',
              backend: {
                service: {
                  name: 'init-dev-container-ssh-service',
                  port: {
                    number: 80,
                  },
                },
              },
            },
          ],
        },
      },
    ],
  },
}

export function deepCopy(obj) {
  if (typeof obj !== 'object' || obj === null) {
    return obj
  }
  const copy = Array.isArray(obj) ? [] : {}
  for (const key in obj) {
    if (Object.prototype.hasOwnProperty.call(obj, key)) {
      copy[key] = deepCopy(obj[key])
    }
  }
  return copy
}
